package com.example.controller;

import com.example.common.response.ServerResponse;
import com.example.dto.DemoDTO;
import com.example.dto.base.PageDTO;
import com.example.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: demo请求控制器
 * @Auther: Swain
 * @Date: 2021/1/11 16:48
 * @Version 1.0.0
 */
@Api(tags = "demo请求控制器")
@Validated
@RestController
@RequestMapping(value = "/demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @PostMapping("/add/single")
    @ApiOperation(value = "新增单个", notes = "新增单个")
    public ServerResponse addSingle(@RequestBody @Validated(DemoDTO.add.class) DemoDTO demoDTO) {
        return demoService.addSingle(demoDTO);
    }

    @PostMapping("/delete/single")
    @ApiOperation(value = "删除单个", notes = "删除单个")
    public ServerResponse deleteSingle(@RequestBody @Validated(DemoDTO.delete.class) DemoDTO demoDTO) {
        return demoService.deleteSingle(demoDTO);
    }

    @PostMapping("/update/single")
    @ApiOperation(value = "修改单个", notes = "修改单个")
    public ServerResponse updateSingle(@RequestBody @Validated(DemoDTO.update.class) DemoDTO demoDTO) {
        return demoService.updateSingle(demoDTO);
    }

    @PostMapping("/find/single")
    @ApiOperation(value = "查询单个", notes = "查询单个")
    public ServerResponse findSingle(@RequestBody @Validated(DemoDTO.findSingle.class) DemoDTO demoDTO) {
        return demoService.findSingle(demoDTO);
    }

    @PostMapping("/find/list/page")
    @ApiOperation(value = "分页查询列表", notes = "分页查询列表")
    public ServerResponse findListPage(@RequestBody @Validated(PageDTO.findListPage.class) DemoDTO demoDTO) {
        return demoService.findListPage(demoDTO);
    }


}
